﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SysRouteLinq.Forms
{
    public partial class EditLinha : Form
    {
        public EditLinha()
        {
            InitializeComponent();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            var selectedIndex = this.listBox1.SelectedIndex;

            if (selectedIndex > 0)
            {
                var itemToMoveUp = this.listBox1.SelectedItem;
                this.listBox1.Items.RemoveAt(selectedIndex);
                this.listBox1.Items.Insert(selectedIndex - 1, itemToMoveUp);
                this.listBox1.SelectedIndex = selectedIndex - 1;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            var selectedIndex = this.listBox1.SelectedIndex;

            if (selectedIndex + 1 < this.listBox1.Items.Count)
            {
                var itemToMoveDown = this.listBox1.SelectedItem;
                this.listBox1.Items.RemoveAt(selectedIndex);
                this.listBox1.Items.Insert(selectedIndex + 1, itemToMoveDown);
                this.listBox1.SelectedIndex = selectedIndex + 1;
            }
        }
    }
}
